package guoanmaker.provider.business.controller;

import guoanmaker.provider.business.model.ProvideCommodity;
import guoanmaker.provider.business.model.ProvideShop;
import guoanmaker.provider.business.repository.ProvideCommodityRepository;
import guoanmaker.provider.business.service.ProvideShopServiceInterface;
import guoanmaker.provider.helper.common.AjaxJson;
import guoanmaker.provider.helper.common.abstractobj.ApiController;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * DESC:
 * Created by JTing on 2017/12/15 10:49
 */
@RestController
@RequestMapping(ApiController.SHOP_URL)
public class ProvideShopController {
    @Autowired
    private ProvideShopServiceInterface provideShopService;
    @Autowired
    private ProvideCommodityRepository provideCommodityRepository;

    /* *
     * @Description:根据商户id查询店铺资料服务中心
     * @author JTing
     * @date 2017/12/15 11:17
     * @param [businessId]
     * @return guoanmaker.provider.helper.common.AjaxJson
     */
    @ApiOperation(value = "根据商户id查询店铺资料服务中心", notes = "根据商户id查询店铺资料服务中心")
    @PostMapping(value = "/selectProvideShop")
    public AjaxJson selectProvideShop(String businessId) {
    	AjaxJson ajaxJson=new AjaxJson();
        Map<String, Object> map = new HashMap<>();
        try {
            map = provideShopService.selectProvideShop(businessId);
            ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(map);
        } catch (Exception e) {
            ajaxJson.setSuccess(false).setStatus(250).setMsg("操作失败").setData(map);
        }
        return ajaxJson;
    }

    /* *
     * @Description:根据商铺id查询店铺资料服务中心
     * @author JTing
     * @date 2017/12/17 15:37
     * @param [shopId]
     * @return guoanmaker.provider.helper.common.AjaxJson
     */
    @ApiOperation(value = "根据商铺id查询店铺资料服务中心", notes = "根据商铺id查询店铺资料服务中心")
    @PostMapping(value = "/selectProvideShopByShopId")
    public AjaxJson selectProvideShopByShopId(String shopId) {
    	AjaxJson ajaxJson=new AjaxJson();
        Map<String, Object> map = new HashMap<>();
        try {
            map = provideShopService.selectProvideShopByShopId(shopId);
            ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(map);
        } catch (Exception e) {
            ajaxJson.setSuccess(false).setStatus(250).setMsg("操作失败").setData(null);
        }
        return ajaxJson;
    }

    /* *
     * @Description:修改店铺资料
     * @author JTing
     * @date 2017/12/18 19:40
     * @param [provideShop]
     * @return guoanmaker.provider.helper.common.AjaxJson
     */
    @ApiOperation(value = "修改店铺资料", notes = "修改店铺资料")
    @PostMapping(value = "/modProvideShop")
    public AjaxJson modProvideShop(@RequestBody ProvideShop provideShop) {
    	AjaxJson ajaxJson=new AjaxJson();
        try {
            Integer i = provideShopService.modProvideShop(provideShop);
            ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(i);
        } catch (Exception e) {
            ajaxJson.setSuccess(false).setStatus(250).setMsg("操作失败").setData(null);
        }
        return ajaxJson;
    }

    /* *
     * @Description:获得商户得分
     * @author JTing
     * @date 2017/12/18 19:41
     * @param [businessId]
     * @return guoanmaker.provider.helper.common.AjaxJson
     */
    @ApiOperation(value = "获得商户得分", notes = "获得商户得分")
    @PostMapping(value = "getProvideShopScore")
    public AjaxJson getProvideShopScore(String businessId) {
    	AjaxJson ajaxJson=new AjaxJson();
        try {
            String score = provideShopService.getProvideShopScore(businessId);
            ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(score);
        } catch (Exception e) {
            ajaxJson.setSuccess(false).setStatus(250).setMsg("操作失败").setData(null);
        }
        return ajaxJson;

    }

    /* *
     * @Description:获得店铺总评价
     * @author JTing
     * @date 2017/12/18 19:42
     * @param [businessId]
     * @return guoanmaker.provider.helper.common.AjaxJson
     */
    @ApiOperation(value = "获得店铺总评价", notes = "获得店铺总评价")
    @PostMapping("getProvideShopScoreDtl")
    public AjaxJson getProvideShopScoreDtl(String businessId) {
    	AjaxJson ajaxJson=new AjaxJson();
        Map<String, Object> map = new HashMap<>();
        try {
            map = provideShopService.getProvideShopScoreDtl(businessId);
            ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(map);
        } catch (Exception e) {
            ajaxJson.setSuccess(false).setStatus(250).setMsg("操作失败").setData(null);
        }
        return ajaxJson;
    }

    /* *
     * @Description:获得商户下的全部商品的评价
     * @author JTing
     * @date 2017/12/18 19:42
     * @param [businessId, page, pageSize, type]
     * @return guoanmaker.provider.helper.common.AjaxJson
     */
    @ApiOperation(value = "获得商户下的全部商品的评价", notes = "获得商户下的全部商品的评价")
    @PostMapping("getBusinessAllAppraise")
    public AjaxJson getBusinessAllAppraise(String businessId, Integer page, Integer pageSize, Integer type) {
    	AjaxJson ajaxJson=new AjaxJson();
    	Map<String, Object> map = new HashMap<>();
        try {
            map = provideShopService.getBusinessAllAppraise(businessId, page, pageSize, type);
            ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(map);
        } catch (Exception e) {
            ajaxJson.setSuccess(false).setStatus(250).setMsg("操作失败").setData(null);
        }
        return ajaxJson;
    }

    /* *
     * @Description:店铺评价列表和总评
     * @author JTing
     * @date 2017/12/18 19:42
     * @param [businessId, page, pageSize, type]
     * @return guoanmaker.provider.helper.common.AjaxJson
     */
    @ApiOperation(value = "店铺评价列表和总评", notes = "店铺评价列表和总评")
    @PostMapping("/shopAppraiseListAndTotal")
    public AjaxJson shopAppraiseListAndTotal(String businessId, Integer page, Integer pageSize, Integer type) {
    	AjaxJson ajaxJson=new AjaxJson();
    	Map<String, Object> map = new HashMap<>();
        try {
            map = provideShopService.getBusinessAllAppraise(businessId, page, pageSize, type);
            map.putAll(provideShopService.getProvideShopScoreDtl(businessId));
            ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(map);
        } catch (Exception e) {
            ajaxJson.setSuccess(false).setStatus(250).setMsg("操作失败").setData(null);
        }
        return ajaxJson;
    }

    /* *
     * @Description:店铺详情(商品id)
     * @author JTing
     * @date 2017/12/17 14:24
     * @param [id]
     * @return guoanmaker.provider.helper.common.AjaxJson
     */
    @ApiOperation(value = "店铺详情(商品id)", notes = "店铺详情(商品id)")
    @PostMapping(value = "/shopDetailByCommid")
    public AjaxJson shopDetailByCommid(String id) {
    	AjaxJson ajaxJson=new AjaxJson();
        Map<String, Object> map = new HashMap<>();
        try {
            ProvideCommodity one = provideCommodityRepository.findOne(id);
            String businessId = one.getProviderBusiness().getId();
            map = provideShopService.shopDetailByBid(businessId);
            ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(map);
        } catch (Exception e) {
            ajaxJson.setSuccess(false).setStatus(250).setMsg("操作失败").setData(null);
        }
        return ajaxJson;
    }

    /* *
     * @Description:店铺详情(商户id)
     * @author JTing
     * @date 2017/12/18 19:42
     * @param [businessId]
     * @return guoanmaker.provider.helper.common.AjaxJson
     */
    @ApiOperation(value = "店铺详情(商户id)", notes = "店铺详情(商户id)")
    @PostMapping(value = "/shopDetailByBusinessId")
    public AjaxJson shopDetailByBusinessId(String businessId) {
    	AjaxJson ajaxJson=new AjaxJson();
        Map<String, Object> map = new HashMap<>();
        try {
            map = provideShopService.shopDetailByBid(businessId);
            ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(map);
        } catch (Exception e) {
            ajaxJson.setSuccess(false).setStatus(250).setMsg("操作失败").setData(null);
        }
        return ajaxJson;
    }

    /* *
     * @Description:店铺详情和用户评价列表
     * @author JTing
     * @date 2017/12/18 19:43
     * @param [businessId, page, pageSize, type]
     * @return guoanmaker.provider.helper.common.AjaxJson
     */
    @ApiOperation(value = "店铺详情和用户评价列表", notes = "店铺详情和用户评价列表")
    @PostMapping("/shopDtlAndAppraiseList")
    public AjaxJson shopDtlAndAppraiseList(String businessId, Integer page, Integer pageSize, Integer type) {
    	AjaxJson ajaxJson=new AjaxJson();
    	Map<String, Object> map = new HashMap<>();
        try {
            map = provideShopService.shopDetailByBid(businessId);
            map.putAll(provideShopService.getBusinessAllAppraise(businessId, page, pageSize, type));
            ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(map);
        } catch (Exception e) {
            ajaxJson.setSuccess(false).setStatus(250).setMsg("操作失败").setData(null);
        }
        return ajaxJson;
    }

    /* *
     * @Description:分页查询店铺下的商品(商品id)
     * @author JTing
     * @date 2017/12/18 19:43
     * @param [id, sid, cityId, page, pageSize, sortType]
     * @return guoanmaker.provider.helper.common.AjaxJson
     */
    @ApiOperation(value = "分页查询店铺下的商品(商品id)", notes = "分页查询店铺下的商品(商品id)")
    @PostMapping(value = "/findShopCommbyCommid")
    public AjaxJson findShopCommbyCommid(String id, String sid, String cityId, Integer page, Integer pageSize, Integer sortType) {
    	AjaxJson ajaxJson=new AjaxJson();
    	Map<String, Object> map = new HashMap<>();
        try {
            ProvideCommodity one = provideCommodityRepository.findOne(id);
            String businessId = one.getProviderBusiness().getId();
            map = provideShopService.findShopComm(businessId, sid, cityId, page, pageSize, sortType);
            ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(map);
        } catch (Exception e) {
            ajaxJson.setSuccess(false).setStatus(250).setMsg("操作失败").setData(null);
        }
        return ajaxJson;

    }

    /* *
     * @Description:分页查询店铺下的商品(商户id)
     * @author JTing
     * @date 2017/12/18 19:44
     * @param [businessId, sid, cityId, page, pageSize, sortType]
     * @return guoanmaker.provider.helper.common.AjaxJson
     */
    @ApiOperation(value = "分页查询店铺下的商品(商户id)", notes = "分页查询店铺下的商品")
    @PostMapping(value = "/findShopCommbyBusinessId")
    public AjaxJson findShopCommbyBusinessId(String businessId, String sid, String cityId, Integer page, Integer pageSize, Integer sortType) {
    	AjaxJson ajaxJson=new AjaxJson();
    	Map<String, Object> map = new HashMap<>();
        try {
            map = provideShopService.findShopComm(businessId, sid, cityId, page, pageSize, sortType);
            ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(map);
        } catch (Exception e) {
            ajaxJson.setSuccess(false).setStatus(250).setMsg("操作失败").setData(null);
        }
        return ajaxJson;

    }

    /* *
     * @Description:商铺中查询商品分类统计
     * @author JTing
     * @date 2017/12/18 19:44
     * @param [businessId, cityId]
     * @return guoanmaker.provider.helper.common.AjaxJson
     */
    @ApiOperation(value = "商铺中查询商品分类统计", notes = "商铺中查询商品分类统计")
    @PostMapping(value = "/shopCommClass")
    public AjaxJson shopCommClass(String businessId, String cityId) {
    	AjaxJson ajaxJson=new AjaxJson();
        Map<String, Object> map = new HashMap<>();
        try {
            map = provideShopService.shopCommClass(businessId, cityId);
            ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(map);
        } catch (Exception e) {
            ajaxJson.setSuccess(false).setStatus(250).setMsg("操作失败").setData(null);
        }
        return ajaxJson;
    }

    /* *
     * @Description:查询店铺可用的城市区域
     * @author JTing
     * @date 2017/12/18 19:44
     * @param [businessId]
     * @return guoanmaker.provider.helper.common.AjaxJson
     */
    @ApiOperation(value = "查询店铺可用的城市区域", notes = "查询店铺可用的城市区域")
    @PostMapping(value = "/findShopComCity")
    public AjaxJson findShopComCity(String businessId) {
    	AjaxJson ajaxJson=new AjaxJson();
        Map<String, Object> map = new HashMap<>();
        try {
            map = provideShopService.findShopComCity(businessId);
            ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(map);
        } catch (Exception e) {
            ajaxJson.setSuccess(false).setStatus(250).setMsg("操作失败").setData(null);
        }
        return ajaxJson;
    }
    /* *
     * @Description:店铺详情和商品列表(商品id)
     * @author JTing
     * @date 2017/12/18 19:51
     * @param [id, sid, cityId, page, pageSize, sortType]
     * @return guoanmaker.provider.helper.common.AjaxJson
     */
    @ApiOperation(value = "店铺详情和商品列表(商品id)", notes = "店铺详情和商品列表(商品id)")
    @PostMapping("/shopDtlAndCommByCid")
    public AjaxJson shopDtlAndCommByCid(String id, String sid, String cityId, Integer page, Integer pageSize, Integer sortType) {
    	AjaxJson ajaxJson=new AjaxJson();
    	Map<String, Object> map = new HashMap<>();
        try {
            ProvideCommodity one = provideCommodityRepository.findOne(id);
            String businessId = one.getProviderBusiness().getId();
            map = provideShopService.findShopComm(businessId, sid, cityId, page, pageSize, sortType);
            map.putAll(provideShopService.shopDetailByBid(businessId));
            ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(map);
        } catch (Exception e) {
            ajaxJson.setSuccess(false).setStatus(250).setMsg("操作失败").setData(null);
        }
        return ajaxJson;
    }
    /* *
     * @Description:店铺详情和商品列表(商户id)
     * @author JTing
     * @date 2017/12/18 19:53
     * @param [businessId, sid, cityId, page, pageSize, sortType]
     * @return guoanmaker.provider.helper.common.AjaxJson
     */
    @ApiOperation(value = "店铺详情和商品列表(商户id)", notes = "店铺详情和商品列表(商户id)")
    @PostMapping("/shopDtlAndCommByid")
    public AjaxJson shopDtlAndCommByBid(String businessId, String sid, String cityId, Integer page, Integer pageSize, Integer sortType) {
    	AjaxJson ajaxJson=new AjaxJson();
    	Map<String, Object> map = new HashMap<>();
        try {
            map = provideShopService.findShopComm(businessId, sid, cityId, page, pageSize, sortType);
            map.putAll(provideShopService.shopDetailByBid(businessId));
            ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(map);
        } catch (Exception e) {
            ajaxJson.setSuccess(false).setStatus(250).setMsg("操作失败").setData(null);
        }
        return ajaxJson;
    }
    /* *
     * @Description:店铺初始化接口(商品id)
     * @author JTing
     * @date 2017/12/20 14:54
     * @param [id, sid, cityId, page, pageSize, sortType, type]
     * @return guoanmaker.provider.helper.common.AjaxJson
     */
    @ApiOperation(value = "店铺初始化接口(商品id)", notes = "店铺初始化接口(商品id)")
    @PostMapping("/shopInitByCid")
    public AjaxJson shopInitByCid (String id, String sid, String cityId, Integer page, Integer pageSize, Integer sortType,Integer type){
    	AjaxJson ajaxJson=new AjaxJson();
        Map<String, Object> map = new HashMap<>();
        try {
            ProvideCommodity one = provideCommodityRepository.findOne(id);
            String businessId = one.getProviderBusiness().getId();  //获取businessId
            map.putAll(provideShopService.shopDetailByBid(businessId));  //获取店铺详情
            map.putAll(provideShopService.findShopComCity(businessId)); //获取可用城市区域
            map.putAll(provideShopService.shopCommClass(businessId,cityId));//获取初始的2级分类
            map.putAll(provideShopService.findShopComm(businessId, sid, cityId, page, pageSize, sortType)); //获取商品列表
            map.putAll(provideShopService.getBusinessAllAppraise(businessId, page, pageSize, type));  //获得店铺评价
            map.putAll(provideShopService.getProvideShopScoreDtl(businessId));//获得用户评价
            ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(map);
        } catch (Exception e) {
            ajaxJson.setSuccess(false).setStatus(250).setMsg("操作失败").setData(null);
        }
        return ajaxJson;

    }
    /* *
     * @Description:店铺初始化接口(商户id)
     * @author JTing
     * @date 2017/12/20 14:55
     * @param [businessId, sid, cityId, page, pageSize, sortType, type]
     * @return guoanmaker.provider.helper.common.AjaxJson
     */
    @ApiOperation(value = "店铺初始化接口(商户id)", notes = "店铺初始化接口(商户id)")
    @PostMapping("/shopInitByBid")
    public AjaxJson shopInitByBid (String businessId, String sid, String cityId, Integer page, Integer pageSize, Integer sortType,Integer type){
    	AjaxJson ajaxJson=new AjaxJson();
        Map<String, Object> map = new HashMap<>();
        try {

            map.putAll(provideShopService.shopDetailByBid(businessId));  //获取店铺详情
            map.putAll(provideShopService.findShopComCity(businessId)); //获取可用城市区域
            map.putAll(provideShopService.shopCommClass(businessId,cityId));   //获取初始的2级分类
            map.putAll(provideShopService.findShopComm(businessId, sid, cityId, page, pageSize, sortType)); //获取商品列表
            map.putAll(provideShopService.getBusinessAllAppraise(businessId, page, pageSize, type));  //获得店铺评价
            map.putAll(provideShopService.getProvideShopScoreDtl(businessId)); //获得用户评价
            ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(map);//获取商品列表

        } catch (Exception e) {
            ajaxJson.setSuccess(false).setStatus(250).setMsg("操作失败").setData(null);
        }
        return ajaxJson;

    }


    /* *
 * @Description:店铺初始化接口(商品id)ForApp
 * @author JTing
 * @date 2017/12/20 14:54
 * @param [id, sid, cityId, page, pageSize, sortType, type]
 * @return guoanmaker.provider.helper.common.AjaxJson
 */
    @ApiOperation(value = "店铺初始化接口(商品id)ForApp", notes = "店铺初始化接口(商品id)ForApp")
    @PostMapping("/shopInitByCidForApp")
    public AjaxJson shopInitByCidForApp (String id, String sid, String cityId, Integer page, Integer pageSize, Integer sortType,Integer type){
    	AjaxJson ajaxJson=new AjaxJson();
        Map<String, Object> map = new HashMap<>();
        try {
            ProvideCommodity one = provideCommodityRepository.findOne(id);
            String businessId = one.getProviderBusiness().getId();  //获取businessId
            map.putAll(provideShopService.shopDetailByBid(businessId));  //获取店铺详情
            map.putAll(provideShopService.findShopComCity(businessId)); //获取可用城市区域
            map.putAll(provideShopService.shopCommClass(businessId,cityId));//获取初始的2级分类
            map.putAll(provideShopService.findShopComm(businessId, sid, cityId, page, pageSize, sortType)); //获取商品列表
            map.putAll(provideShopService.getBusinessAllAppraise(businessId, 0, 10, type));  //获得店铺评价
            map.putAll(provideShopService.getProvideShopScoreDtl(businessId));//获得用户评价
            ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(map);
        } catch (Exception e) {
            ajaxJson.setSuccess(false).setStatus(250).setMsg("操作失败").setData(null);
        }
        return ajaxJson;

    }
    /* *
     * @Description:店铺初始化接口(商户id)ForApp
     * @author JTing
     * @date 2017/12/20 14:55
     * @param [businessId, sid, cityId, page, pageSize, sortType, type]
     * @return guoanmaker.provider.helper.common.AjaxJson
     */
    @ApiOperation(value = "店铺初始化接口(商户id)ForApp", notes = "店铺初始化接口(商户id)ForApp")
    @PostMapping("/shopInitByBidForApp")
    public AjaxJson shopInitByBidForApp (String businessId, String sid, String cityId, Integer page, Integer pageSize, Integer sortType,Integer type){
    	AjaxJson ajaxJson=new AjaxJson();
        Map<String, Object> map = new HashMap<>();
        try {

            map.putAll(provideShopService.shopDetailByBid(businessId));  //获取店铺详情
            map.putAll(provideShopService.findShopComCity(businessId)); //获取可用城市区域
            map.putAll(provideShopService.shopCommClass(businessId,cityId));   //获取初始的2级分类
            map.putAll(provideShopService.findShopComm(businessId, sid, cityId, page, pageSize, sortType)); //获取商品列表
            map.putAll(provideShopService.getBusinessAllAppraise(businessId, 0, 10, type));  //获得店铺评价
            map.putAll(provideShopService.getProvideShopScoreDtl(businessId)); //获得用户评价
            ajaxJson.setSuccess(true).setStatus(200).setMsg("操作成功").setData(map);//获取商品列表

        } catch (Exception e) {
            ajaxJson.setSuccess(false).setStatus(250).setMsg("操作失败").setData(null);
        }
        return ajaxJson;

    }

}

